<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="css/template.css">
		<link rel="stylesheet" type="text/css" href="css/TestTaking.css">
		<link rel="stylesheet" type="text/css" href="css/smoothness/jquery-ui-1.10.0.custom.css" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		
		<script type="text/javascript" src="JQuery/jquery-1.9.0.min.js"></script>
		<script type="text/javascript" src="JQuery/jquery-ui-1.10.0.custom.js"></script>	
		<script type="text/javascript" src="JS/TestTaking.js"></script>
		<title>Page Title</title>
	</head>
	<body>
	<?php
		require("webservices.php");
        
		// Grab bacic information about test
		require_once('session_handler.php');
        session_handler_start();
		
        $testinfo = Get_test_basic_info($_GET['trid']);
		
		$CourseName  = $testinfo[0]['CourseName'];
		$TestName 	 = $testinfo[0]['TestName'];
		$Description = $testinfo[0]['Description'];
		$TestLength  = $testinfo[0]['TestLength'] . " mins";
		$Instructor  = $testinfo[0]['Instructor'];
		$Pledge      = $testinfo[0]['Pledge'];
		$TestRecordID = $testinfo[0]['TestRecordID'];

		// Check if the user already login
		if(!isset($_SESSION['userid'])) 
		{
			header('Location: firstpage.php?field=LoginFirst');
			exit();
		}
	?>
	
		<div id="main">
			
			<div id="TopBoard">
				<img src="images/redpen-01.png" alt="RedPenLogo" id="RedPenLogo"/>
				<span id="AuthInfo">
					<span id="Avatar">
						<?php
							echo '<img src="images/avatar/' . $_SESSION['avatar'] .'" id="AvatarImg" />';
						?>
					</span> 
					<span id="UserName">
					<?php
						echo $_SESSION['username'];
					?>
					</span>
					<span id="Power" style="display: none">
					
					</span>
					<span id="LogOut"><a href="logout.php" id="LogoutLink">Logout</a></span>
				</span>
			</div>
			
			<div id="HeaderBar"></div>
			
			<div id="Content">	
				<div id="TestInfo" class="TestPart">
					<div class="TestPartContainer">
						<span id="TestName"><?php echo $TestName; ?></span>
						<br/><br/>
						<span class="TestInfoLabel">Course</span><span class="TestInfoValue"><?php echo $CourseName; ?></span>
						<br/>
						<span class="TestInfoLabel">Course Instructor</span><span class="TestInfoValue"><?php echo $Instructor; ?></span>
						<br/>
						<span class="TestInfoLabel">Test Length</span><span class="TestInfoValue"><?php echo $TestLength; ?></span>
						<br/>
						<span class="TestInfoLabel">Description</span><span class="TestInfoValue"><?php echo $Description; ?></span>
					<?php
						
						
						// Grab bacic information about test
					
						$testinfo = Get_test_basic_info($_GET['trid'], $_SESSION['userid']);
						
						if(array_key_exists('ErrorMsg', $testinfo[0]))
						{
							echo '<img src="images/error.png" class="ErrorIcon" /><span class="ErrorMsg">' . $testinfo[0]['ErrorMsg'] . '</span>';
							exit();
						}
						else
						{
						$CourseName   = $testinfo[0]['CourseName'];
						$TestName 	  = $testinfo[0]['TestName'];
						$Description  = $testinfo[0]['Description'];
						$TestLength   = $testinfo[0]['TestLength'] . " mins";
						$Instructor   = $testinfo[0]['Instructor'];
						$Pledge       = $testinfo[0]['Pledge'];
						$TestRecordID = $testinfo[0]['TestRecordID'];
						
						echo '<span id="TestName">' .  $TestName . '</span>';
						echo '<br/>';
						}
					?>
					
						
					</div>
				</div>
				<form id="TestForm" action="SubmitTest.php" method="post">
				<form id="TestForm" action="" method="post">
				<div id="TestQuestions" class="TestPart">
					<div class="TestPartContainer">
						
				<?php
					$Questions = Get_test_questions($_GET['trid']);
					$Questions = Get_test_questions($_GET['trid'], $_SESSION['userid']);
					$TrueFalse = false;
					$MultipleChoice = false;
					$ShortAnswer = false;
					$Essay = false;
					$Matching = false;
					$ChooseAll = false;
					$QuestionNumber = 1;
					
					if(array_key_exists('ErrorMsg', $Questions[0]))
					{
						echo $Questions[0]['ErrorMsg'];
						exit();
					}
							
					echo '<input type="text" id="TestRecordID" class="hidden" name="RecordID" value="' . $TestRecordID . '" />';
					
					foreach($Questions as $Question)
					{
						if($Question['QType'] == 1)
						{
							
						
							if(!$TrueFalse)
							{
								echo '<br/><span class="TestSectionHeader">True or False</span>';
								$TrueFalse = true;
								$MultipleChoice = false;
								$ShortAnswer = false;
								$Essay = false;
								$Matching = false;
								$ChooseAll = false;
							}	
							echo '<br/><br/><span class="QuestionNumber">' . $QuestionNumber . '. </span>';
							echo '<span class="QuestionText">' . $Question['Question'] . ' (' . $Question['Points'] . ')</span>';
							echo '<br/><span class="answers">';
							echo '<input class="OptionRadio" type="radio" name="' . $Question['id'] . '" value="1"> True</input>';
							echo '<br/><input class="OptionRadio" type="radio" name="' . $Question['id'] . '" value="2"> False</input>';
							echo '</span>';
						}
						else if ($Question['QType'] == 2)
						{
							if(!$MultipleChoice)
							{
								echo '<br/><br/><span class="TestSectionHeader">Multiple Choice</span>';
								$MultipleChoice = true;
								$TrueFalse = false;
								$ShortAnswer = false;
								$Essay = false;
								$Matching = false;
								$ChooseAll = false;
							}	
							echo '<br/><br/><span class="QuestionNumber">' . $QuestionNumber . '. </span>';
							echo '<span class="QuestionText">' . $Question['Question'] . ' (' . $Question['Points'] . ')</span>';
							$Options = explode(',', $Question['options']);
							$Options_id = explode(',', $Question['options_id']);
							echo '<br/><span class="answers">';
							foreach($Options as $Index => $Option)
							{
								echo '<input class="OptionRadio" type="radio" name="' . $Question['id'] . '" value="'. $Options_id[$Index] . '"> ' . $Option . '</input><br/>';
							}
							echo '</span>';
						}
						else if ($Question['QType'] == 4)
						{
							if(!$ChooseAll)
							{
								echo '<br/><br/><span class="TestSectionHeader">Choose All That Apply</span>';
								$ChooseAll = true;
								$ShortAnswer = false;
								$MultipleChoice = false;
								$TrueFalse = false;
								$Essay = false;
								$Matching = false;
							}	
							echo '<br/><br/><span class="QuestionNumber">' . $QuestionNumber . '. </span>';
							echo '<span class="QuestionText">' . $Question['Question'] . ' (' . $Question['Points'] . ')</span>';
							$Options = explode(',', $Question['options']);
							$Options_id = explode(',', $Question['options_id']);
							echo '<br/><span class="answers">';
							foreach($Options as $Index => $Option)
							{
								echo '<input class="OptionRadio" type="checkbox" name="' . $Question['id'] . '" value="'. $Options_id[$Index] . '"> ' . $Option . '</input><br/>';
								echo '<input class="OptionRadio" type="checkbox" name="' . $Question['id'] . '[]" value="'. $Options_id[$Index] . '"> ' . $Option . '</input><br/>';
							}
							echo '</span>';
							

						}
						
						
						else if ($Question['QType'] == 5)
						{
							if(!$ShortAnswer)
							{
								echo '<br/><br/><span class="TestSectionHeader">Short Answer</span>';
								$ShortAnswer = true;
								$MultipleChoice = false;
								$TrueFalse = false;
								$Essay = false;
								$Matching = false;
								$ChooseAll = false;
							}	
							echo '<br/><br/><span class="QuestionNumber">' . $QuestionNumber . '. </span>';
							echo '<span class="QuestionText">' . $Question['Question'] . ' (' . $Question['Points'] . ')</span>';
							echo '<br/><span class="answers">';
							echo '<input type="text" class="ShortAnswerBox" name="' . $Question['id'] . '" />';
							echo '</span>';
							

						}
						
						else if ($Question['QType'] == 6)
						{
							if(!$Essay)
							{
								echo '<br/><br/><span class="TestSectionHeader">Essay</span>';
								$Essay = true;
								$MultipleChoice = false;
								$TrueFalse = false;
								$ShortAnswer = false;
								$Matching = false;
								$ChooseAll = false;
							}	
							echo '<br/><br/><span class="QuestionNumber">' . $QuestionNumber . '. </span>';
							echo '<span class="QuestionText">' . $Question['Question'] . ' (' . $Question['Points'] . ')</span>';
							echo '<br/><span class="answers">';
							echo '<textarea name="' . $Question['id'] . '" class="EssayBox" cols="50" rows="5" form="TestForm"></textarea>';	
							echo '</span>';
							

						}
						
						$QuestionNumber++;
					}
					
					
				?>
					</div>
				</div>
				<div id="TestPledge" class="TestPart">
				<div class="TestPartContainer">
				<span id="PledgeHeader">Pledge</span><br/><br/>
				<?php
					echo $Pledge;				
				?>
				<br/><br/>
				<span id="PledgeName">
				<span id="PledgeNameLabel">Please type your name</span>
				<input type="text" id="PledgeNameBox" name="PledgeName" />
				</span>
				
				</div>
				</div>
				
				<div id="Buttons">
				<input type="submit" id="SubmitButton" value="Complete Test" />
					
				<input type="button" id="SubmitButton" onClick="return false;" value="Complete Test" />
				<input type="button" id="TestButton" value="Test" />	
				</div>
				</form>
				
			</div>
			<div id="ConfirmDialog" title="Confirm Pledge" style="display:none;">
				<img src="images/warning.png" id="DialogIcon" /><span id="DialogMessage">You have not signed the pledge. Do you still want to continue?</span>
			</div>
			<div id="footer">
				<div id="HeaderBar"></div>
				<br/>
				<span id="Copyright">
					&#169; Team Flash 2013
					<br/>Pensacola Christian College
				</span>
				<br/>
			</div>		
		</div>
	</body>
			
</html>


